﻿

#region Using Statements

// System References
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;

// XNA References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// Internal References
using Freeform.Framework.Graphics;

#endregion


namespace Freeform.Framework.Utility
{
    /// <summary>
    /// Provides some useful static Math functions.
    /// </summary>
    public abstract class MathLib
    {

        #region Members

        /// <summary>
        /// Gets or sets the underlying System.Random class used to generate random numbers.
        /// </summary>
        private static System.Random _Random { get; set; }
        public static System.Random Random { get { if (_Random == null) _Random = new Random(); return _Random; } }

        #endregion


        #region Utility

        /// <summary>
        /// Returns a unit Vector2 in the direction specified.
        /// </summary>
        /// <param name="Direction">The direction for the unit vector, in radians.</param>
        /// <returns>A unit vector in the given direction.</returns>
        public static Vector2 Vec2InDir(Single Direction)
        {
            return new Vector2((Single)Math.Sin(Direction), -(Single)Math.Cos(Direction));
        }


        /// <summary>
        /// Generates a random floating-point precision value between the given bounds.
        /// </summary>
        /// <param name="lowerBound">The lower bound on the value.</param>
        /// <param name="upperBound">The upper bound on the value.</param>
        /// <returns>A random number.</returns>
        public static Single Single(Single lowerBound, Single upperBound)
        {
            return (Single)(Random.NextDouble() * (upperBound - lowerBound) + lowerBound);
        }


        /// <summary>
        /// Generates a random double floating-point precision value between the given bounds.
        /// </summary>
        /// <param name="lowerBound">The lower bound on the value.</param>
        /// <param name="upperBound">The upper bound on the value.</param>
        /// <returns>A random number.</returns>
        public static Double Double(Double lowerBound, Double upperBound)
        {
            return Random.NextDouble() * (upperBound - lowerBound) + lowerBound;
        }


        /// <summary>
        /// Generates a random integer between the given bounds.
        /// </summary>
        /// <param name="lowerBound">The lower bound on the value. (Inclusive)</param>
        /// <param name="upperBound">The upper bound on the value. (Exclusive)</param>
        /// <returns>A random number.</returns>
        public static Int32 Int32(Int32 lowerBound, Int32 upperBound)
        {
            return Random.Next(lowerBound, upperBound);
        }

        #endregion

    }
}
